package com.itheima.练习.test6;

import com.itheima.练习.test5.MyRunnable;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.*;

//服务器
public class Server {
    public static void main(String[] args) throws IOException {
        //创建线程池对象
        ThreadPoolExecutor poolExecutor=new ThreadPoolExecutor(//线程池7个
                3,
                16,
                60,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(2),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()
        );

        ServerSocket ss=new ServerSocket(10000);

        //循环可以一直上传，但是如果未上传完毕一个就上传第二个就会报错

        while (true) {
            Socket socket = ss.accept();
            //new Thread(new MyRunnable(socket)).start();
            poolExecutor.submit(new MyRunnable(socket));
        }
    }
}
